//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_squadmgmtlbchanged.sqf"
#include "x_setup.sqf"

#include "x_uiinc.sqf"

private ["_idc", "_car", "_idx", "_ctrl", "_diff", "_grp", "_disp", "_button", "_lbsel"];
if (GVAR(sqtmgmtblocked)) exitWith {};
PARAMS_2(_idc,_car);
_idx = _car select 1;
if (_idx == -1) exitWith {};
_ctrl = _car select 0;
_diff = _idc - 2000;

_grp = GVAR(SQMGMT_grps) select _diff;
disableSerialization;
_disp = __uiGetVar(X_SQUADMANAGEMENT_DIALOG);
_button = 3000 + _diff;

if (group player == _grp && {player == leader _grp}) then {
	_lbsel = _ctrl lbText _idx;
	if (name player != _lbsel) then {
		CTRL(_button) ctrlSetText "Remove";
	} else {
		CTRL(_button) ctrlSetText "Leave";
	};
};